home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Macintosh / Development & Resource Tools / MacsBug6.5.3.sit / MacsBug 6.5.3 / Building dcmds / C Samples / Vbl.c < prev    next >
Text File  |  1996-02-22  |  4KB  |  177 lines

  1. /*
  2.     File:        VBL.c
  3.  
  4.     Contains:    A dcmd which displays onboard and slot-based VBL tasks.
  5.  
  6.     Written by:    JM3 = Jim Murphy
  7.                 DAL = Dave Lyons
  8.                 sad = Scott Douglas
  9.  
  10.     Copyright:    © 1988, 1993-1994, 1996 by Apple Computer, Inc., All Rights Reserved.
  11.  
  12.     Change History (most recent first):
  13.  
  14.          <4>   25-Jan-96    JM3        Updated the sample build commands to be current.
  15.          <3>   11-Dec-94    JM3        Updated for new version 3 dcmd requirements. Removed the remnants of Dave's
  16.                                      old wiggy brace style. Luckily, that habit has long since been broken. :-)
  17.          <2>      9/9/93    DAL        now displays all nonempty SlotVBL queues as well as the regular
  18.                                     VBL queue; cleaned up the output
  19.  
  20.     Modification history:
  21.          2Dec88 sad        written from VCB.
  22.  
  23.     The following MPW commands will build the dcmd and copy it to the "Debugger Prefs" file
  24.     in the System folder. The dcmd's name in MacsBug will be the name of the file built by
  25.     the Linker.
  26.  
  27.     C VBL.c
  28.     Link -o VBL -sg Main=STDCLIB,STDIO,SANELIB dcmdGlue.a.o" Put.c.o" VBL.c.o" ∂
  29.         "{Libraries}Runtime.o"
  30.     BuildDcmd VBL 197 -format3
  31.     Echo 'include "VBL";'    |    Rez -a -o "{SystemFolder}Debugger Prefs"
  32.  
  33.     TO DO
  34.     -----
  35.     identify the task's owner in some way
  36. */
  37.  
  38. #include <Memory.h>
  39. #include <OSUtils.h>
  40. #include <Retrace.h>
  41. #include <Types.h>
  42.  
  43. #include "dcmd.h"
  44. #include "put.h"
  45.  
  46. #define VBLQueue ((QHdrPtr)0x160)
  47.  
  48.  
  49. static void DrawVBL(VBLTask* vblp)
  50. {
  51.  
  52.     PutUHexZTo((unsigned long)vblp,8,8);
  53.     PutSpacesTo(10);
  54.     PutUHexWord(vblp->vblCount);
  55.     PutSpacesTo(17);
  56.     PutUHexWord(vblp->vblPhase);
  57.     PutSpacesTo(24);
  58.     PutUHexZTo((unsigned long)vblp->vblAddr,8,27);
  59.     PutLine();
  60.  
  61. }
  62.  
  63.  
  64. void DumpOneVBLQueue(QHdrPtr theQueue, short slotNum, dcmdBlock* paramPtr)
  65. {
  66.  
  67.     VBLTask* vblp;
  68.     int numvbls = 0;
  69.  
  70.     PutLine();
  71.     PutPStr("\pVBL tasks");
  72.     if(slotNum != -1)
  73.     {
  74.         PutPStr("\p for slot ");
  75.         PutUDec(slotNum);
  76.     }
  77.  
  78.     if (theQueue->qFlags & 0x4000)
  79.         PutPStr("\p (queue executing)");
  80.     else
  81.         PutPStr("\p (queue not executing)");
  82.     PutLine();
  83.  
  84.     vblp = (VBLTask*)(theQueue->qHead);
  85.  
  86. //                             1         2         3         4         5         6         7
  87. //                    1234567890123456789012345678901234567890123456789012345678901234567890
  88.     dcmdDrawLine("\p VBLTask  Count  Phase  Code");
  89.     dcmdDrawLine("\p -------  -----  -----  ----");
  90.  
  91.     while (vblp)
  92.     {
  93.         DrawVBL(vblp);
  94.         numvbls++;
  95.         if (paramPtr->aborted) break;
  96.         if (vblp->qLink == 0)
  97.             if (vblp != (VBLTask*)(theQueue->qTail))
  98.                 dcmdDrawLine("\pVBL queue does not end at VBLQueue.qTail");
  99.         vblp = (VBLTask*)vblp->qLink;
  100.     }
  101.  
  102.     PutUDec(numvbls);
  103.     if(numvbls==1)
  104.         PutPStr("\p VBL task");
  105.     else
  106.         PutPStr("\p VBL tasks");
  107.     PutLine();
  108.  
  109. }
  110.  
  111.  
  112. short GetQueueSize(QHdrPtr theQueue)
  113. {
  114.  
  115.     VBLTask* vblp;
  116.     int count = 0;
  117.  
  118.     vblp = (VBLTask*)(theQueue->qHead);
  119.  
  120.     while (vblp)
  121.     {
  122.         count++;
  123.         if(count>1000)
  124.             return count;    // avoid infinite loop if queue is hosed
  125.         vblp = (VBLTask*)vblp->qLink;
  126.     }
  127.  
  128.     return count;
  129.  
  130. }
  131.  
  132.  
  133. pascal void CommandEntry(dcmdBlock* paramPtr)
  134. {
  135.  
  136.     static const char usageStr[] = "\p";
  137.  
  138.     switch (paramPtr->request)
  139.     {
  140.         case dcmdInit:
  141.             break;
  142.  
  143.         case dcmdHelp:
  144.             dcmdDrawLine("\pLists tasks in the regular and slot VBL queues.");
  145.             break;
  146.  
  147.         case dcmdGetInfo:
  148.             * (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03008000; // version 3.0 final
  149.             BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
  150.             break;
  151.  
  152.         case dcmdDoIt:
  153.         {
  154.             short slotNum;
  155.             QHdrPtr *slotQueueArray = *(QHdrPtr **)0x0D04;
  156.             
  157.             dcmdSwapWorlds();
  158.  
  159.             DumpOneVBLQueue(VBLQueue,-1,paramPtr);
  160.             for(slotNum=0; slotNum<=14; slotNum++)
  161.             {
  162.                 if(GetQueueSize(slotQueueArray[slotNum]))
  163.                     DumpOneVBLQueue(slotQueueArray[slotNum], slotNum, paramPtr);
  164.             }
  165.  
  166.             dcmdSwapWorlds();
  167.         }
  168.             break;
  169.  
  170.         // Version 3 and newer dcmds must quietly ignore requests we don't recognize.
  171.  
  172.         default:
  173.             break;
  174.     }
  175.  
  176. }
  177.